package com.lingyu.jsjx.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.lingyu.jsjx.domain.StaffInfo;
import com.lingyu.jsjx.service.IStaffInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 教师信息Controller
 *
 * @author ruoyi
 * @date 2025-08-08
 */
@RestController
@RequestMapping("/staffInfo")
public class StaffInfoController extends BaseController {
    @Autowired
    private IStaffInfoService staffInfoService;


    /**
     * 查询教师信息列表
     */
    @RequiresPermissions("jsjx:staffInfo:list")
    @GetMapping("/list")
    public TableDataInfo list(StaffInfo staffInfo) {
        startPage();
        List<StaffInfo> list = staffInfoService.selectStaffInfoList(staffInfo);
        return getDataTable(list);
    }

    /**
     * 导出教师信息列表
     */
    @RequiresPermissions("jsjx:staffInfo:export")
    @Log(title = "教师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StaffInfo staffInfo) {
        List<StaffInfo> list = staffInfoService.selectStaffInfoList(staffInfo);
        ExcelUtil<StaffInfo> util = new ExcelUtil<StaffInfo>(StaffInfo.class);
        util.exportExcel(response, list, "教师信息数据");
    }

    /**
     * 获取教师信息详细信息
     */
    @RequiresPermissions("jsjx:staffInfo:query")
    @GetMapping(value = "/{staffId}")
    public AjaxResult getInfo(@PathVariable("staffId") Long staffId) {
        QueryWrapper<StaffInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("create_by", staffId);
        StaffInfo staffInfo = staffInfoService.getOne(queryWrapper);
        return success(staffInfo);
    }

    /**
     * 新增教师信息
     */
    @RequiresPermissions("jsjx:staffInfo:add")
    @Log(title = "教师信息", businessType = BusinessType.INSERT)
    @PostMapping
    @Transactional
    public AjaxResult add(@RequestBody StaffInfo staffInfo) throws Exception {
        return toAjax(staffInfoService.insertStaffInfo(staffInfo));
    }

    /**
     * 修改教师信息
     */
    @RequiresPermissions("jsjx:staffInfo:edit")
    @Log(title = "教师信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StaffInfo staffInfo) {
        return toAjax(staffInfoService.updateStaffInfo(staffInfo));
    }

    /**
     * 删除教师信息
     */
    @RequiresPermissions("jsjx:staffInfo:remove")
    @Log(title = "教师信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{staffIds}")
    public AjaxResult remove(@PathVariable Long[] staffIds) {
        return toAjax(staffInfoService.deleteStaffInfoByStaffIds(staffIds));
    }
}
